//
//  RBGoodsDetailHeaderView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/16.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  商品详情 tableView表头

#import "RBGoodsDetailHeaderView.h"
#import <SDCycleScrollView.h>

@interface RBGoodsDetailHeaderView()
/**轮播图*/
@property(nonatomic, strong) SDCycleScrollView *cycleSrollView;

/**轮播图下面 商品信息 背景view*/
@property(nonatomic, strong) UIView *goodsInfoBgView;
@property(nonatomic, strong) UILabel *nameLb;

@property(nonatomic, strong) UIView *smallbgView; //找个<div>￥56 ￥67 0人付款</div>装


/**价格*/
@property(nonatomic, strong) UILabel *priceLb;
/**原价*/
@property(nonatomic, strong) UILabel *originPriceLb;
/**付款人数*/
@property(nonatomic, strong) UILabel *payNumberLb;
@end

@implementation RBGoodsDetailHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

#pragma mark - 赋值
- (void)configRBGoodsDetailHeaderViewImages:(NSArray *)imageArr name:(NSString *)name price:(NSString *)price originPrice:(NSString *)yuanjia payCount:(NSString *)payNum {
    
    [self.cycleSrollView setImageURLStringsGroup:imageArr];
    
    self.nameLb.text = [NSString stringWithFormat:@"%@",name];
    self.priceLb.text = [NSString stringWithFormat:@"￥%.2f",[price floatValue]];
    
    //添加中划线
    NSString *originPriceStr = [NSString stringWithFormat:@"￥%.2f",[yuanjia floatValue]];
    self.originPriceLb.attributedText = [self zhongHuaXianWithStr:originPriceStr];
//    self.originPriceLb.text = [NSString stringWithFormat:@"￥%.2f",[yuanjia floatValue]];
    self.payNumberLb.text = [NSString stringWithFormat:@"%d人付款",[payNum intValue]];
}

//添加中划线

- (NSAttributedString *)zhongHuaXianWithStr:(NSString  *)priceString {
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];

    return attribtStr;
}



- (void)setupUI{
    [self addSubview:self.cycleSrollView];
    [self addSubview:self.goodsInfoBgView];
    [self.goodsInfoBgView addSubview:self.nameLb];

    [self.goodsInfoBgView addSubview:self.smallbgView];
    

    // 这三个控件用一个div装
    [self.smallbgView addSubview:self.priceLb];
    [self.smallbgView addSubview:self.originPriceLb];
    [self.smallbgView addSubview:self.payNumberLb];
}
#pragma mark - getter
- (SDCycleScrollView *)cycleSrollView {
    if (!_cycleSrollView) {
        //        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, KWidth, ADAPTHeight(375)) delegate:self placeholderImage:[UIImage imageWithColor:XJCOLOR_RGB(221, 221, 221)]];
        _cycleSrollView = [[SDCycleScrollView alloc] init];
        _cycleSrollView.backgroundColor = [UIColor whiteColor];
    }
    return _cycleSrollView;
}
- (UIView *)goodsInfoBgView {
    if (!_goodsInfoBgView) {
        _goodsInfoBgView = [[UIView alloc] init];
    }
    return _goodsInfoBgView;
}
- (UILabel *)nameLb{
    if (!_nameLb) {
        _nameLb = [[UILabel alloc] init];
        _nameLb.numberOfLines = 0;
    }
    return _nameLb;
}

- (UIView *)smallbgView {
    if (!_smallbgView) {
        _smallbgView = [[UIView alloc] init];
    }
    return _smallbgView;
}

- (UILabel *)priceLb {
    if (!_priceLb) {
        _priceLb = [[UILabel alloc] init];
        _priceLb.textColor = [UIColor redColor];
    }
    return _priceLb;
}

- (UILabel *)originPriceLb {
    if (!_originPriceLb) {
        _originPriceLb = [[UILabel alloc] init];
        _originPriceLb.textColor = [UIColor lightGrayColor];
        _originPriceLb.font = [UIFont systemFontOfSize:13.0];
    }
    return _originPriceLb;
}

- (UILabel *)payNumberLb {
    if (!_payNumberLb) {
        _payNumberLb = [[UILabel alloc] init];
        _payNumberLb.textColor = [UIColor lightGrayColor];
        _payNumberLb.font = [UIFont systemFontOfSize:13.0];
    }
    return _payNumberLb;
}

#pragma mark - layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 宽高固定(频宽、375)
    [self.cycleSrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(ADAPTHeight(375));
    }];
    
    
    // (屏幕宽,100)
    [self.goodsInfoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.cycleSrollView.mas_bottom);
        make.height.mas_equalTo(ADAPTHeight(60));
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsInfoBgView.mas_left).offset(10);
        make.top.equalTo(self.goodsInfoBgView.mas_top).offset(10);
        make.height.mas_equalTo(ADAPTHeight(20));
        make.width.mas_equalTo(ADAPTWidth(200));
    }];
    
    [self.smallbgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLb.mas_bottom).offset(5);
        make.left.bottom.right.equalTo(self.goodsInfoBgView);
    }];
    
    
    [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.smallbgView.mas_left).offset(10);
//        make.top.bottom.equalTo(self.smallbgView);
//        make.width.mas_equalTo(ADAPTWidth(100));
//        make.left.top.bottom.equalTo(self.smallbgView);
        make.left.equalTo(self.smallbgView.mas_left).offset(10);
        make.top.bottom.equalTo(self.smallbgView);
        make.width.mas_equalTo(ADAPTWidth(100));
    }];
    
    [self.originPriceLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.priceLb.mas_right).offset(5);
//        make.bottom.equalTo(self.smallbgView.mas_bottom);
//        make.size.mas_equalTo(CGSizeMake(ADAPTWidth(100), ADAPTHeight(20)));
//        make.left.equalTo(self.priceLb.mas_right).offset(5);
//        make.bottom.equalTo(self.goodsInfoBgView.mas_bottom).offset(-10);
//        make.width.mas_equalTo(100);
//        make.height.mas_equalTo(20);
        
        make.top.bottom.equalTo(self.smallbgView);
        make.left.equalTo(self.priceLb.mas_right).offset(10);
        make.width.mas_equalTo(ADAPTWidth(100));
    }];
    
    [self.payNumberLb mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.right.equalTo(self.smallbgView);
        make.width.mas_equalTo(ADAPTWidth(80));
        
//        make.right.equalTo(self.goodsInfoBgView.mas_right).offset(-10);
//        make.bottom.equalTo(self.goodsInfoBgView.mas_bottom).offset(-10);
//        make.width.mas_equalTo(60);
//        make.height.mas_equalTo(20);
    }];
    
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
